Go uses a concurrent tri-color mark-and-sweep GC that runs mostly alongside the program. GOGC controls heap growth trigger and GOMEMLIMIT (Go 1.19+) sets a soft memory ceiling.
Tri-color mark and sweep: objects are white (not visited), grey (reachable but children not scanned), or black (fully scanned)
Concurrent: GC mark phase runs alongside the program — very short stop-the-world pauses (<1ms)
Write barrier: ensures correctness when the mutator (your code) modifies pointers during GC
Sweep phase reclaims white objects after mark completes
GC is triggered when heap size doubles since last GC (controlled by GOGC)
Profile first with pprof heap profiles before tuning GC parameters
GOGC=off + GOMEMLIMIT: disable time-based GC, rely on memory limit for triggering — good for batch jobs
Reduce allocations using sync.Pool for frequently allocated objects
Avoid pointer-heavy data structures — GC must trace every pointer
Use GODEBUG=gctrace=1 to see GC pause times and heap sizes in logs